<?php

namespace common\models\db\tables;

use Yii;

/**
 * This is the model class for table "{{%equipment_operate_log}}".
 *
 * @property string $id
 * @property string $equipment_id 设备id
 * @property string $action_route 路由
 * @property string $req_data 请求信息
 * @property string $resp_data 响应信息
 * @property int $created_at 操作时间
 * @property int $status 状态
 * @property string $for_equipment_user 操作的设备用户
 * @property int $operate_type 操作类型
 *
 * @property Equipment $equipment
 * @property EquipmentUser $forEquipmentUser
 */
class EquipmentOperateLog extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%equipment_operate_log}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['equipment_id', 'action_route', 'req_data', 'created_at'], 'required'],
            [['equipment_id', 'created_at', 'status', 'for_equipment_user', 'operate_type'], 'integer'],
            [['req_data', 'resp_data'], 'string'],
            [['action_route'], 'string', 'max' => 191],
            [['equipment_id'], 'exist', 'skipOnError' => true, 'targetClass' => Equipment::className(), 'targetAttribute' => ['equipment_id' => 'id']],
            [['for_equipment_user'], 'exist', 'skipOnError' => true, 'targetClass' => EquipmentUser::className(), 'targetAttribute' => ['for_equipment_user' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'equipment_id' => Yii::t('app', '设备id'),
            'action_route' => Yii::t('app', '路由'),
            'req_data' => Yii::t('app', '请求信息'),
            'resp_data' => Yii::t('app', '响应信息'),
            'created_at' => Yii::t('app', '操作时间'),
            'status' => Yii::t('app', '状态'),
            'for_equipment_user' => Yii::t('app', '操作的设备用户'),
            'operate_type' => Yii::t('app', '操作类型'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipment()
    {
        return $this->hasOne(Equipment::className(), ['id' => 'equipment_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getForEquipmentUser()
    {
        return $this->hasOne(EquipmentUser::className(), ['id' => 'for_equipment_user']);
    }
}